package com.banggood.upms.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author XuChuangFeng
 * @date 2017/5/10
 */
public class TimeUtils {

    static String CN_TIME_ZONE = "Asia/Shanghai";

    static String FULL_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String getCurrentTimeStr() {
        return getCurrentTimeStr(FULL_FORMAT);
    }

    public static String getCurrentTimeStr(String format) {
        Date currentTime = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone(CN_TIME_ZONE));
        return simpleDateFormat.format(currentTime);
    }

    public static Date StringToTime(String format, String stringTime) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = simpleDateFormat.parse(stringTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

}
